using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace UmlDesigner.Model
{
    [Serializable]
    class SortedSet<KeyType, ValueType> : CollectionBase, IEnumerable
    {
        public SortedSet()
        {
        }

        public void Add(KeyType key, ValueType value)
        {
            if (!data.ContainsKey(key))
            {
                data[key] = new List<ValueType>();
            }
            data[key].Add(value);
        }

        public void Remove(KeyType key)
        {
            if (data.ContainsKey(key))
            {
                data.Remove(key);
            }
        }

        public new IEnumerator GetEnumerator() 
        {
            foreach (KeyValuePair<KeyType, List<ValueType>> bucket in data)
            {
                foreach (ValueType value in bucket.Value)
                {
                    yield return new KeyValuePair<KeyType, ValueType>(bucket.Key, value);
                }
            }
        }

        private SortedDictionary<KeyType, List<ValueType>> data = new SortedDictionary<KeyType, List<ValueType>>();

    }
}
